package com.eedi.framework.org.framework.context;

import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.eedi.framework.mybatis.config.EediMybatisAutoConfiguration;
import com.eedi.framework.mybatis.core.handler.DefaultDBFieldHandler;
import com.eedi.framework.mybatis.core.handler.OrgContextInterface;
import com.eedi.framework.mybatis.core.handler.TenantContextInterface;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;


@AutoConfiguration(before = EediMybatisAutoConfiguration.class)
public class OrgContextConfig {

    @Bean
    @Primary
    public MetaObjectHandler defaultMetaObjectHandler(){
        OrgContextInterface orgContext = SpringUtil.getBean(OrgContextInterface.class);
        TenantContextInterface tenantContext = SpringUtil.getBean(TenantContextInterface.class);
        return new DefaultDBFieldHandler(orgContext, tenantContext);
        // 自动填充参数类
    }

}
